from pyecharts import options as opts
from pyecharts.charts import Pie

ages = ['>=50', '[40,50)', '[30,40)', '[20,30)']
percentages = [12.5, 20.8, 29.2, 37.5]

colors = ["#C3E2EC", "#CECCE5", "#F7C4C1", "#BCD1BC"]

pie = (
    Pie(init_opts=opts.InitOpts(width="800px", height="600px"))
    .add(
        series_name="年龄分布",
        data_pair=[(age, percentage) for age, percentage in zip(ages, percentages)],
        radius=["40%", "70%"],
        rosetype="radius",
        color=colors,
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="年龄分布图"),
        legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%"),
    )
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c} ({d}%)"))
)

# 显示图表
pie.render("D:/python charm/01/可视化/第二章/图片/南丁格尔圆环图.html")